﻿using System.Collections.Generic;
using System.Data.Entity;
using System.Linq;
using IceDog.DNF.Program.Mvc5.EfContext;
using IceDog.DNF.Program.Mvc5.Models;

namespace IceDog.DNF.Program.Mvc5.Repository
{
    public class SystemUserRepository : ISystemUserRepository
    {
        protected AccountContext db;
        public SystemUserRepository()
        {
            db = new AccountContext();
        }
        public List<SystemUser> GetAllSystemUser()
        {
            return db.SystemUsers.ToList();
        }

        public void AddSystemUser(SystemUser user)
        {
            db.SystemUsers.Add(user);
            db.SaveChanges();
        }

        public void EditSystemUser(SystemUser user)
        {
            db.Entry(user).State = EntityState.Modified;
            db.SaveChanges();
        }

        public void RemoveSystemUser(int userId)
        {
            var systemUser = db.SystemUsers.Find(userId);
            if (systemUser != null)
            {
                db.SystemUsers.Remove(systemUser);
                db.SaveChanges();
            }
        }
    }
}